#include "xinterpret.h"
#include <iostream>
#include <vector>

using namespace std;

extern Display *display;

void XIMovePointer(int xpos, int ypos, bool relative)
{
Display *display = XOpenDisplay(0);
if (relative)
    XTestFakeRelativeMotionEvent(display, xpos, ypos, 0);
else
    XTestFakeMotionEvent(display, -1, xpos, ypos, 0);
/*
// Create some variables to hold the return values from XQueryPointer
	Window root_return, child_return;
	int root_x_return, root_y_return, win_x_return, win_y_return;
	unsigned int mask_return;

// Get current pointer coordinates --- X = root_x_return, Y = root_y_return
XQueryPointer(display, 
              rootwin, 
              &root_return, 
              &child_return, 
              &root_x_return, 
              &root_y_return, 
              &win_x_return, 
              &win_y_return, 
              &mask_return);

// Calculate relative position of new coordinates from old coordinates
int rel_x = xpos - root_x_return,
    rel_y = ypos - root_y_return;

// Move the pointer to the new location
XWarpPointer(display, None, None, 0, 0, 0, 0, rel_x, rel_y);
*/
XCloseDisplay(display);
return;
}

void XIUseKeyboard(int keycode, bool release)
{
Display *display = XOpenDisplay(0);
XTestFakeKeyEvent(display, keycode, !release, 0);
XCloseDisplay(display);
return;
}

void XIClickMouse(int button, bool release)
{
Display *display = XOpenDisplay(0);
XTestFakeButtonEvent(display, button, !release, 0);
XCloseDisplay(display);
return;
}


KeyCode get_x_keycode_from_string(string keystr)
{
KeySym sym = XStringToKeysym(keystr.c_str());
KeyCode code = XKeysymToKeycode(display, sym);
return code;
} 

